#ifndef __LOG_HH_
#define __LOG_HH_

#include "log.h"
#include <iostream>
#include <sstream>

namespace log{
class Log{
public:
    Log(int level, const char* color,
        const char *fileName __attribute__((unused)),
        const char *func __attribute__((unused)),
        int line __attribute__((unused))) :
        logLevel(level),color(color){
            if (fileName != NULL && line != 0){
#if PRINT_FMT == 0
                p_stream << "[ " << fileName << " @ " << line << " ] ";
#elif PRINT_FMT == 1
                p_stream << "[ " << func << "(" << line << ") ] ";
#endif
            }
        }

    ~Log(){
        if ( logLevel <= LOG_LEVEL ) {
#if SYSLOG_DEBUG == 0
#elif SYSLOG_DEBUG == 1
            syslog( logLevel, "%s\n", p_stream.str().c_str() );
#elif SYSLOG_DEBUG == 2
            syslog( logLevel, "%s\n", p_stream.str().c_str() );
            printf( "%s%s\n" DEFAULT, color != NULL? color: DEFAULT, p_stream.str().c_str() );
#else
            printf( "%s%s\n" DEFAULT, color != NULL? color: DEFAULT, p_stream.str().c_str() );
#endif
        }
    }

    std::ostream& stream(){return p_stream;}

private:
    const int logLevel = LOG_DEBUG;
    const char* color = NULL;
    std::ostringstream p_stream;
};
}

#define LogD()\
    ::log::Log(LOG_DEBUG, DEFAULT, __FILE__, __func__, __LINE__).stream()

#define LogI()\
    ::log::Log(LOG_INFO, GREEN, __FILE__, __func__, __LINE__).stream()

#define LogW()\
    ::log::Log(LOG_WARNING, YELLOW, __FILE__, __func__, __LINE__).stream()

#define LogE()\
    ::log::Log(LOG_ERR, RED, __FILE__, __func__, __LINE__).stream()

#endif
